import './assets/main.css'
import './assets/fonts.css'
import './assets/variables.css'
import './assets/main.css'

// 导入Element Plus及其样式
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import pinia from './stores'
import { useUserStore } from './stores/user'

const app = createApp(App)
app.use(pinia)
app.use(router)
app.use(ElementPlus)

// 等待用户信息初始化完成后再挂载应用
const userStore = useUserStore()
console.log('应用初始化前 - token:', localStorage.getItem('token'))
console.log('应用初始化前 - userId:', localStorage.getItem('userId'))
userStore
  .initUserInfo(router)
  .then(() => {
    console.log('用户信息初始化成功后 - userInfo:', userStore.userInfo)
    app.mount('#app')
  })
  .catch((error) => {
    console.error('初始化应用失败:', error)
    console.log('初始化失败后 - token:', localStorage.getItem('token'))
    console.log('初始化失败后 - userId:', localStorage.getItem('userId'))
    // 即使初始化失败，也挂载应用
    app.mount('#app')
  })
